//
//  DLDealBgScrollView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/19.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLDealBgScrollView.h"
#import "DLDealBgView.h"

@implementation DLDealBgScrollView

- (instancetype) initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.loadedIndex = [NSMutableArray array];
    }
    return self;
}


- (void) updateDealWithCurrentPage:(NSInteger)currentPage andDataSource:(NSArray *)dataSource {
    
    
    if (![self.loadedIndex containsObject:@(currentPage)]) {
        NSLog(@"没加载过这个页面，新创建");
        _dealView = [[DLDealBgView alloc] initWithFrame:CGRectMake(self.width *currentPage, 0, self.width, self.height)];
        _dealView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_dealView];
    } else {
        NSLog(@"加载过这个页面了,不需要新创建");
    }
    
    NSLog(@"不论是否加载过 都需要刷新数据");
    _dealView.dealViewDataSource = self.dealDataSource;
    
    if (![self.loadedIndex containsObject:@(currentPage)]) {
        [self.loadedIndex addObject:@(currentPage)];
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
